package com.lin.cms.service.impl;

import java.util.List;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.lin.cms.util.Paging;
import com.lin.cms.criteria.ModelItemCriteria;
import com.lin.cms.domain.ModelItem;
import com.lin.cms.service.ModelItemService;
import com.lin.cms.dao.ModelItemMapper;

@Service
public class ModelItemServiceImpl implements ModelItemService{
	
	public ModelItem selectByPrimaryKey(Integer modelitemId){
		return modelItemMapper.selectByPrimaryKey(modelitemId);
	}
	
	public List<ModelItem> selectByCriteria(ModelItemCriteria criteria){
		return modelItemMapper.selectByCriteria(criteria);
	}
	
	public int deleteByPrimaryKey(Integer modelitemId){
		int actualRowsAffected = 0;
		
		ModelItem _oldModelItem = modelItemMapper.selectByPrimaryKey(modelitemId);
		
		if (_oldModelItem != null) {
			actualRowsAffected = modelItemMapper.deleteByPrimaryKey(modelitemId);
		}
		
		return actualRowsAffected;
	}
	
	public int deleteByCriteria(ModelItemCriteria criteria){
		int actualRowsAffected = 0;
		
		List<ModelItem> _oldModelItem = modelItemMapper.selectByCriteria(criteria);
		
		if (_oldModelItem.size() != 0) {
			actualRowsAffected = modelItemMapper.deleteByCriteria(criteria);
		}
		
		return actualRowsAffected;
	}
	
	public int insert(ModelItem modelItem){
		return modelItemMapper.insert(modelItem);
	}
	
	public int updateByPrimaryKeySelective(ModelItem modelItem){
		int actualRowsAffected = 0;
		
		int advertisingId = modelItem.getModelitemId();

		ModelItem _oldModelItem = modelItemMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldModelItem != null) {
			actualRowsAffected = modelItemMapper.updateByPrimaryKeySelective(modelItem);
		}
		
		return actualRowsAffected;
	}
	
	public int updateByPrimaryKey(ModelItem modelItem){
		int actualRowsAffected = 0;
		
		int advertisingId = modelItem.getModelitemId();

		ModelItem _oldModelItem = modelItemMapper.selectByPrimaryKey(advertisingId);
		
		if (_oldModelItem != null) {
			actualRowsAffected = modelItemMapper.updateByPrimaryKey(modelItem);
		}
		
		return actualRowsAffected;
	}
	
	public List<ModelItem> selectByPage(ModelItemCriteria criteria) {
		int totalResults = modelItemMapper.countByCriteria(criteria);
		Paging paging = criteria.getPaging();
		paging.setTotalResults(totalResults);
		
		return modelItemMapper.selectByPage(criteria,new RowBounds(paging.getFirstResult(),paging.getMaxResults()));
	}
	
	public int countByCriteria(ModelItemCriteria criteria){
		return modelItemMapper.countByCriteria(criteria);
	}
	
	public List<ModelItem> getList(Integer modelId, boolean isChannel,
			boolean hasDisabled) {
		// TODO Auto-generated method stub
		List<ModelItem> m=modelItemMapper.getList(modelId, isChannel, hasDisabled);
		return m;
	}
	
	@Autowired
    private ModelItemMapper modelItemMapper;

}
